﻿namespace H2.Streams
{
    using H2.DataTypes;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Runtime.CompilerServices;
    using System.Text;

    public class BaseStream
    {
        protected string __filePath;
        private string __status__;
        private Stack<long> _bookmarks;
        protected BinaryReader br;
        protected BinaryWriter bw;
        protected System.IO.Stream stream;

        public event StatusChangeHandler StatusChanged;

        public BaseStream(System.IO.Stream baseStream, StatusChangeHandler statusChangedHandler)
        {
            this.StatusChanged = (StatusChangeHandler) Delegate.Combine(this.StatusChanged, statusChangedHandler);
            this.stream = baseStream;
            this.br = new BinaryReader(this.stream);
            this.bw = new BinaryWriter(this.stream);
            this._bookmarks = new Stack<long>();
        }

        public BaseStream(string filepath, StatusChangeHandler statusChangedHandler)
        {
            this.StatusChanged = (StatusChangeHandler) Delegate.Combine(this.StatusChanged, statusChangedHandler);
            this.__filePath = filepath;
            this.stream = new FileStream(this.FilePath, FileMode.Open);
            this.br = new BinaryReader(this.stream);
            this.bw = new BinaryWriter(this.stream);
            this._bookmarks = new Stack<long>();
        }

        public void Close()
        {
            this.br.Close();
            this.Status = "Map Closed";
        }

        public void Flush()
        {
            this.Status = "Saving Changes...";
            this.bw.Flush();
        }

        public void PopBookmark()
        {
            this.stream.Position = this._bookmarks.Pop();
        }

        public void PushBookmark()
        {
            this._bookmarks.Push(this.stream.Position);
        }

        public Bitmask ReadBitmask(int ByteCount)
        {
            return new Bitmask(this.br.ReadBytes(ByteCount));
        }

        public Bitmask ReadBitmask(int ByteCount, bool RetainCurrentPosition)
        {
            byte[] bytes = this.br.ReadBytes(ByteCount);
            if (RetainCurrentPosition)
            {
                this.Position -= ByteCount;
            }
            return new Bitmask(bytes);
        }

        public Bitmask ReadBitmaskAt(int Offset, int ByteCount, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            byte[] bytes = this.br.ReadBytes(ByteCount);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            return new Bitmask(bytes);
        }

        public byte ReadByte()
        {
            return this.br.ReadByte();
        }

        public byte ReadByte(bool RetainCurrentPosition)
        {
            byte num = this.br.ReadByte();
            if (RetainCurrentPosition)
            {
                this.Position -= 1L;
            }
            return num;
        }

        public byte ReadByteAt(int Offset, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            byte num2 = this.br.ReadByte();
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            return num2;
        }

        public byte[] ReadBytes(int Count)
        {
            return this.br.ReadBytes(Count);
        }

        public byte[] ReadBytes(int Count, bool RetainCurrentPosition)
        {
            byte[] buffer = this.br.ReadBytes(Count);
            if (RetainCurrentPosition)
            {
                this.Position -= Count;
            }
            return buffer;
        }

        public byte[] ReadBytesAt(int Offset, int Count, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            byte[] buffer = this.br.ReadBytes(Count);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            return buffer;
        }

        public char[] ReadChars(int Count)
        {
            char[] chArray = new char[Count];
            for (int i = 0; i < Count; i++)
            {
                chArray[i] = Convert.ToChar(this.br.ReadByte());
            }
            return chArray;
        }

        public char[] ReadChars(int Count, bool RetainCurrentPosition)
        {
            char[] chArray = new char[Count];
            for (int i = 0; i < Count; i++)
            {
                chArray[i] = Convert.ToChar(this.br.ReadByte());
            }
            if (RetainCurrentPosition)
            {
                this.Position -= Count;
            }
            return chArray;
        }

        public char[] ReadCharsAt(int Offset, int Count, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            char[] chArray = new char[Count];
            for (int i = 0; i < Count; i++)
            {
                chArray[i] = Convert.ToChar(this.br.ReadByte());
            }
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            return chArray;
        }

        public H2.DataTypes.Enum ReadEnum(int ByteCount)
        {
            if (ByteCount == 1)
            {
                return new H2.DataTypes.Enum(this.ReadByte());
            }
            if (ByteCount == 2)
            {
                return new H2.DataTypes.Enum(this.ReadInt16());
            }
            if (ByteCount == 4)
            {
                return new H2.DataTypes.Enum(this.ReadInt32());
            }
            if (ByteCount == 8)
            {
                return new H2.DataTypes.Enum(this.ReadInt64());
            }
            return null;
        }

        public H2.DataTypes.Enum ReadEnum(int ByteCount, bool RetainCurrentPosition)
        {
            H2.DataTypes.Enum enum2 = null;
            if (ByteCount == 1)
            {
                enum2 = new H2.DataTypes.Enum(this.ReadByte());
            }
            else if (ByteCount == 2)
            {
                enum2 = new H2.DataTypes.Enum(this.ReadInt16());
            }
            else if (ByteCount == 4)
            {
                enum2 = new H2.DataTypes.Enum(this.ReadInt32());
            }
            else if (ByteCount == 8)
            {
                enum2 = new H2.DataTypes.Enum(this.ReadInt64());
            }
            if (RetainCurrentPosition)
            {
                this.Position -= ByteCount;
            }
            return enum2;
        }

        public H2.DataTypes.Enum ReadEnumAt(int Offset, int ByteCount, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            H2.DataTypes.Enum enum2 = null;
            if (ByteCount == 1)
            {
                enum2 = new H2.DataTypes.Enum(this.ReadByte());
            }
            else if (ByteCount == 2)
            {
                enum2 = new H2.DataTypes.Enum(this.ReadInt16());
            }
            else if (ByteCount == 4)
            {
                enum2 = new H2.DataTypes.Enum(this.ReadInt32());
            }
            else if (ByteCount == 8)
            {
                enum2 = new H2.DataTypes.Enum(this.ReadInt64());
            }
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            return enum2;
        }

        public H2.DataTypes.String ReadFixedLengthString(H2.DataTypes.Length length)
        {
            return new H2.DataTypes.String(length, Encoding.UTF8, this.ReadBytes((int) length));
        }

        public H2.DataTypes.String ReadFixedLengthString(H2.DataTypes.Length length, bool RetainCurrentPosition)
        {
            return new H2.DataTypes.String(length, Encoding.UTF8, this.ReadBytes((int) length, RetainCurrentPosition));
        }

        public H2.DataTypes.String ReadFixedLengthString(H2.DataTypes.Length length, Encoding encoding)
        {
            return new H2.DataTypes.String(length, encoding, this.ReadBytes((int) length));
        }

        public H2.DataTypes.String ReadFixedLengthString(H2.DataTypes.Length length, Encoding encoding, bool RetainCurrentPosition)
        {
            return new H2.DataTypes.String(length, encoding, this.ReadBytes((int) length, RetainCurrentPosition));
        }

        public H2.DataTypes.String ReadFixedLengthStringAt(int Offset, H2.DataTypes.Length length, bool RetainCurrentPosition)
        {
            return new H2.DataTypes.String(length, Encoding.UTF8, this.ReadBytesAt(Offset, (int) length, RetainCurrentPosition));
        }

        public H2.DataTypes.String ReadFixedLengthStringAt(int Offset, H2.DataTypes.Length length, Encoding encoding, bool RetainCurrentPosition)
        {
            return new H2.DataTypes.String(length, encoding, this.ReadBytesAt(Offset, (int) length, RetainCurrentPosition));
        }

        public float ReadFloat()
        {
            return this.br.ReadSingle();
        }

        public float ReadFloat(bool RetainCurrentPosition)
        {
            float num = this.br.ReadSingle();
            if (RetainCurrentPosition)
            {
                this.Position -= 2L;
            }
            return num;
        }

        public float ReadFloatAt(int Offset, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            float num2 = this.br.ReadSingle();
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            return num2;
        }

        public short ReadInt16()
        {
            return this.br.ReadInt16();
        }

        public short ReadInt16(bool RetainCurrentPosition)
        {
            short num = this.br.ReadInt16();
            if (RetainCurrentPosition)
            {
                this.Position -= 2L;
            }
            return num;
        }

        public short ReadInt16At(int Offset, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            short num2 = this.br.ReadInt16();
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            return num2;
        }

        public int ReadInt32()
        {
            return this.br.ReadInt32();
        }

        public int ReadInt32(bool RetainCurrentPosition)
        {
            int num = this.br.ReadInt32();
            if (RetainCurrentPosition)
            {
                this.Position -= 4L;
            }
            return num;
        }

        public int ReadInt32At(int Offset, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            int num2 = this.br.ReadInt32();
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            return num2;
        }

        public long ReadInt64()
        {
            return this.br.ReadInt64();
        }

        public long ReadInt64(bool RetainCurrentPosition)
        {
            long num = this.br.ReadInt64();
            if (RetainCurrentPosition)
            {
                this.Position -= 8L;
            }
            return num;
        }

        public long ReadInt64At(int Offset, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            long num2 = this.br.ReadInt64();
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            return num2;
        }

        public string ReadNullTerminatedString()
        {
            string str = "";
            for (int i = 0; i < this.Length; i++)
            {
                char ch = Convert.ToChar(this.br.ReadByte());
                if (ch == '\0')
                {
                    return str;
                }
                str = str + ch;
            }
            return str;
        }

        public string ReadNullTerminatedString(bool RetainCurrentPosition)
        {
            string str = "";
            for (int i = 0; i < this.Length; i++)
            {
                char ch = Convert.ToChar(this.br.ReadByte());
                if (ch == '\0')
                {
                    if (RetainCurrentPosition)
                    {
                        this.Position -= i - 1;
                    }
                    return str;
                }
                str = str + ch;
            }
            return str;
        }

        public string ReadNullTerminatedStringAt(int Offset, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < this.Length; i++)
            {
                char ch = Convert.ToChar(this.br.ReadByte());
                if (ch == '\0')
                {
                    if (RetainCurrentPosition)
                    {
                        this.Position = position;
                    }
                    break;
                }
                builder.Append(ch);
            }
            return builder.ToString();
        }

        public string ReadReverseString(int CharCount, bool removeNull)
        {
            char[] array = this.ReadChars(CharCount);
            Array.Reverse(array);
            if (!removeNull)
            {
                return new string(array);
            }
            return new string(array).Split(new char[1])[0];
        }

        public string ReadReverseString(int CharCount, bool removeNull, bool RetainCurrentPosition)
        {
            char[] array = this.ReadChars(CharCount, RetainCurrentPosition);
            Array.Reverse(array);
            if (!removeNull)
            {
                return new string(array);
            }
            return new string(array).Split(new char[1])[0];
        }

        public string ReadReverseStringAt(int Offset, int CharCount, bool removeNull, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            char[] array = this.ReadChars(CharCount);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            Array.Reverse(array);
            if (!removeNull)
            {
                return new string(array);
            }
            return new string(array).Split(new char[1])[0];
        }

        public string ReadString(int CharCount, bool removeNull)
        {
            char[] chArray = this.ReadChars(CharCount);
            if (!removeNull)
            {
                return new string(chArray);
            }
            return new string(chArray).Split(new char[1])[0];
        }

        public string ReadString(int CharCount, bool removeNull, bool RetainCurrentPosition)
        {
            char[] chArray = this.ReadChars(CharCount, RetainCurrentPosition);
            if (!removeNull)
            {
                return new string(chArray);
            }
            return new string(chArray).Split(new char[1])[0];
        }

        public string ReadStringAt(int Offset, int CharCount, bool removeNull, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            char[] chArray = this.ReadChars(CharCount);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            if (!removeNull)
            {
                return new string(chArray);
            }
            return new string(chArray).Split(new char[1])[0];
        }

        public ushort ReadUInt16()
        {
            return this.br.ReadUInt16();
        }

        public ushort ReadUInt16(bool RetainCurrentPosition)
        {
            ushort num = this.br.ReadUInt16();
            if (RetainCurrentPosition)
            {
                this.Position -= 2L;
            }
            return num;
        }

        public ushort ReadUInt16At(int Offset, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            ushort num2 = this.br.ReadUInt16();
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            return num2;
        }

        public uint ReadUInt32()
        {
            return this.br.ReadUInt32();
        }

        public uint ReadUInt32(bool RetainCurrentPosition)
        {
            uint num = this.br.ReadUInt32();
            if (RetainCurrentPosition)
            {
                this.Position -= 4L;
            }
            return num;
        }

        public uint ReadUInt32At(int Offset, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            uint num2 = this.br.ReadUInt32();
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            return num2;
        }

        public ulong ReadUInt64()
        {
            return this.br.ReadUInt64();
        }

        public ulong ReadUInt64(bool RetainCurrentPosition)
        {
            ulong num = this.br.ReadUInt64();
            if (RetainCurrentPosition)
            {
                this.Position -= 8L;
            }
            return num;
        }

        public ulong ReadUInt64At(int Offset, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            ulong num2 = this.br.ReadUInt64();
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            return num2;
        }

        public string ReadUnicodeString(int CharCount, bool removeNull)
        {
            string str = Encoding.Unicode.GetString(this.br.ReadBytes(CharCount));
            if (removeNull)
            {
                return str.Split(new char[1])[0];
            }
            return str;
        }

        public string ReadUnicodeString(int CharCount, bool removeNull, bool RetainCurrentPosition)
        {
            string str = Encoding.Unicode.GetString(this.ReadBytes(CharCount, RetainCurrentPosition));
            if (removeNull)
            {
                return str.Split(new char[1])[0];
            }
            return str;
        }

        public string ReadUnicodeStringAt(int Offset, int CharCount, bool removeNull, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            string str = Encoding.Unicode.GetString(this.br.ReadBytes(CharCount));
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
            if (removeNull)
            {
                return str.Split(new char[1])[0];
            }
            return str;
        }

        public void ReOpen()
        {
            this.Status = "Opening Map...";
            this.stream = new FileStream(this.FilePath, FileMode.Open);
            this.br = new BinaryReader(this.stream);
            this.bw = new BinaryWriter(this.stream);
        }

        public void Write(byte value)
        {
            this.bw.Write(value);
        }

        public void Write(byte[] value)
        {
            this.bw.Write(value);
        }

        public void Write(char[] value)
        {
            this.bw.Write(Encoding.UTF8.GetBytes(value));
        }

        public void Write(string value)
        {
            this.Write(Encoding.UTF8.GetBytes(value.ToCharArray()));
        }

        public void Write(char value)
        {
            this.bw.Write(Encoding.UTF8.GetBytes(new char[] { value })[0]);
        }

        public void Write(Bitmask Bits)
        {
            this.bw.Write(Bitmask.ConvertToByteArray(Bits));
        }

        public void Write(H2.DataTypes.Enum Enum)
        {
            if (Enum.ByteCountLength == 1)
            {
                this.bw.Write((byte) Enum.Value);
            }
            else if (Enum.ByteCountLength == 2)
            {
                this.bw.Write((short) Enum.Value);
            }
            else if (Enum.ByteCountLength == 4)
            {
                this.bw.Write((int) Enum.Value);
            }
            else if (Enum.ByteCountLength == 8)
            {
                this.bw.Write(Enum.Value);
            }
        }

        public void Write(H2.DataTypes.String value)
        {
            int byteCount = value.Encoding.GetByteCount(value.ToCharArray());
            value.Value = value.Value + new string(value.Encoding.GetChars(new byte[(int)value.Length - byteCount]));
            this.Write(value.Encoding.GetBytes(value.ToCharArray()));
        }

        public void Write(short value)
        {
            this.bw.Write(value);
        }

        public void Write(int value)
        {
            this.bw.Write(value);
        }

        public void Write(long value)
        {
            this.bw.Write(value);
        }

        public void Write(float value)
        {
            this.bw.Write(value);
        }

        public void Write(ushort value)
        {
            this.bw.Write(value);
        }

        public void Write(uint value)
        {
            this.bw.Write(value);
        }

        public void Write(ulong value)
        {
            this.bw.Write(value);
        }

        public void Write(Bitmask Bits, bool RetainCurrentPosition)
        {
            this.bw.Write(Bitmask.ConvertToByteArray(Bits));
            if (RetainCurrentPosition)
            {
                this.Position -= Bits.ByteCountLength;
            }
        }

        public void Write(byte value, bool RetainCurrentPosition)
        {
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position -= 1L;
            }
        }

        public void Write(char value, bool RetainCurrentPosition)
        {
            this.bw.Write(Encoding.UTF8.GetBytes(new char[] { value })[0]);
            if (RetainCurrentPosition)
            {
                this.Position -= 1L;
            }
        }

        public void Write(short value, bool RetainCurrentPosition)
        {
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position -= 2L;
            }
        }

        public void Write(int value, bool RetainCurrentPosition)
        {
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position -= 4L;
            }
        }

        public void Write(long value, bool RetainCurrentPosition)
        {
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position -= 8L;
            }
        }

        public void Write(float value, bool RetainCurrentPosition)
        {
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position -= 4L;
            }
        }

        public void Write(ushort value, bool RetainCurrentPosition)
        {
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position -= 2L;
            }
        }

        public void Write(uint value, bool RetainCurrentPosition)
        {
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position -= 4L;
            }
        }

        public void Write(ulong value, bool RetainCurrentPosition)
        {
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position -= 8L;
            }
        }

        public void Write(H2.DataTypes.Enum Enum, bool RetainCurrentPosition)
        {
            if (Enum.ByteCountLength == 1)
            {
                this.bw.Write((byte) Enum.Value);
            }
            else if (Enum.ByteCountLength == 2)
            {
                this.bw.Write((short) Enum.Value);
            }
            else if (Enum.ByteCountLength == 4)
            {
                this.bw.Write((int) Enum.Value);
            }
            else if (Enum.ByteCountLength == 8)
            {
                this.bw.Write(Enum.Value);
            }
            if (RetainCurrentPosition)
            {
                this.Position -= Enum.ByteCountLength;
            }
        }

        public void Write(byte[] value, bool RetainCurrentPosition)
        {
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position -= value.Length;
            }
        }

        public void Write(H2.DataTypes.String value, bool RetainCurrentPosition)
        {
            int byteCount = value.Encoding.GetByteCount(value.ToCharArray());
            value.Value = value.Value + new string(value.Encoding.GetChars(new byte[(int)value.Length - byteCount]));
            this.Write(value.Encoding.GetBytes(value.ToCharArray()));
            if (RetainCurrentPosition)
            {
                this.Position -= (long) value.Length;
            }
        }

        public void Write(char[] value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.bw.Write(Encoding.UTF8.GetBytes(value));
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void Write(string value, bool RetainCurrentPosition)
        {
            this.Write(Encoding.UTF8.GetBytes(value.ToCharArray()));
            if (RetainCurrentPosition)
            {
                this.Position -= value.Length;
            }
        }

        public void WriteAt(int Offset, Bitmask Bits, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.bw.Write(Bitmask.ConvertToByteArray(Bits));
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, H2.DataTypes.Enum Enum, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            if (Enum.ByteCountLength == 1)
            {
                this.bw.Write((byte) Enum.Value);
            }
            else if (Enum.ByteCountLength == 2)
            {
                this.bw.Write((short) Enum.Value);
            }
            else if (Enum.ByteCountLength == 4)
            {
                this.bw.Write((int) Enum.Value);
            }
            else if (Enum.ByteCountLength == 8)
            {
                this.bw.Write(Enum.Value);
            }
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, H2.DataTypes.String value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            int byteCount = value.Encoding.GetByteCount(value.ToCharArray());
            value.Value = value.Value + new string(value.Encoding.GetChars(new byte[(int)value.Length - byteCount]));
            this.Write(value.Encoding.GetBytes(value.ToCharArray()));
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, byte[] value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, byte value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, char[] value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.Write(new string(value));
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, char value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, short value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, int value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, long value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, float value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, string value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.Write(Encoding.UTF8.GetBytes(value.ToCharArray()));
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, ushort value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, uint value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteAt(int Offset, ulong value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            this.bw.Write(value);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteReverseString(char[] value)
        {
            Array.Reverse(value);
            this.Write(value);
            Array.Reverse(value);
        }

        public void WriteReverseString(string value)
        {
            char[] array = value.ToCharArray();
            Array.Reverse(array);
            this.Write(array);
        }

        public void WriteReverseString(char[] value, bool RetainCurrentPosition)
        {
            Array.Reverse(value);
            this.Write(value);
            Array.Reverse(value);
            if (RetainCurrentPosition)
            {
                this.Position -= value.Length;
            }
        }

        public void WriteReverseString(string value, bool RetainCurrentPosition)
        {
            char[] array = value.ToCharArray();
            Array.Reverse(array);
            this.Write(array);
            if (RetainCurrentPosition)
            {
                this.Position -= array.Length;
            }
        }

        public void WriteReverseStringAt(int Offset, char[] value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            Array.Reverse(value);
            this.Write(value);
            Array.Reverse(value);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public void WriteReverseStringAt(int Offset, string value, bool RetainCurrentPosition)
        {
            long position = this.Position;
            this.Position = Offset;
            char[] array = value.ToCharArray();
            Array.Reverse(array);
            this.Write(array);
            if (RetainCurrentPosition)
            {
                this.Position = position;
            }
        }

        public string FilePath
        {
            get
            {
                return this.__filePath;
            }
        }

        public long Length
        {
            get
            {
                return this.stream.Length;
            }
        }

        public long Position
        {
            get
            {
                return this.stream.Position;
            }
            set
            {
                this.stream.Position = value;
            }
        }

        public string Status
        {
            get
            {
                return this.__status__;
            }
            set
            {
                if (this.StatusChanged != null)
                {
                    this.__status__ = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString() + " - " + value;
                    this.StatusChanged(this.__status__);
                }
            }
        }

        public System.IO.Stream Stream
        {
            get
            {
                return this.stream;
            }
        }

        public delegate void StatusChangeHandler(string Status);
    }
}

